

/*
The following codes generate Tables 11 and 12.
*/



************************Table 11***********************************************
************************Table 11***********************************************
************************Table 11***********************************************



cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

rename citycode city

cap drop _merge

merge m:m city t using  "D:\Nanjing\2020\wage gap\data\adjustcost2"
* xtset newid t
 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)


gen lnabsG_gdp=ln(absG_gdp)



* generate DDD term to capture geographic variation in firing costs
*drop DDD1 DDD2 DDD3 DDD4 DDD5 DDD6 DDD7 DDD8 DDD9 DDD10




gen DDD1=did*log(mw_ave1)
gen DDD2=did*log(mw_ave2)

gen DDD3=did*log(train_city)
gen DDD4=did*log(train_ave2)

gen DDD5=did*log(wage_city)
gen DDD6=did*log(wage_ave1)
gen DDD7=did*log(wage_ave2)

gen DDD8=did*log(arbitrament)
gen DDD9=did*log(arbi_ave1)
gen DDD10=did*log(arbi_ave2)



winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0


/*
cap drop DDD7
cap drop ddd
egen ddd=min(wage_ave2)
gen DDD7=did*log(ddd/wage_ave1)
*/

*11.1 column 1: minimum wage
reghdfe lnabsG_gdp DDD1 did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   

*11.2. column 2: average wage
reghdfe lnabsG_gdp DDD7 did  Llnl Ltfp_op   Llnage  LlnkL  LlnRD    export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   



*11.3. column 3: labor disputes

reghdfe lnabsG_gdp DDD9 did  Llnl Ltfp_op   Llnage  LlnkL LlnRD    export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ,  ///
absorb(t newid) cluster (ind4year)   


















************************Table 12***********************************************
************************Table 12***********************************************
************************Table 12***********************************************



*---------------------------------------
* Part I: for labor efficiency gaps
*---------------------------------------
cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear
  rename citycode city
  merge m:m city ind4_adj t using  "city1998-2007.dta" 

  rename city_cic4_value import
keep if _merge==1|_merge==3
replace import=1 if import==.

drop _merge 

 merge m:m city ind4_adj t using  "fdi1998-2007.dta" 
rename city_cic_fdi fdi
replace fdi=1 if fdi==0
keep if _merge==3

rename city citycode
gen num=1
bysort citycode ind4_adj t: egen agg_num=sum(num) /*number of firms at city-industry-year level*/
bysort citycode ind4_adj t: egen agg_rev=sum(s_rev) /*city-industry-year level sales*/
bysort citycode ind4_adj t: egen agg_l=sum(n)      /*city-industry-year level labor scale*/
bysort ind4_adj t: egen  agg_firm=sum(num)   /*city-industry-year level number of firms*/



replace agg_num=log(agg_num)
replace agg_rev=log(agg_rev)
replace agg_l=log(agg_l)
gen agg_imp=log(import)
gen agg_fdi=log(fdi)
gen ave_export=s_ind_exp/agg_firm
replace ave_export=log(ave_export)
replace ave_export=0 if ave_export==.
/*
duplicates drop newid t, force
xtset newid t
bysort newid: gen Lagg_imp=l.agg_imp
bysort newid: gen Lagg_l=l.agg_l
*/

 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)

 
 gen lnn=log(n)
 sort newid t
 xtset newid t
 bysort newid: gen lnn_l=l.lnn
 gen diff_n=abs(lnn-lnn_l)
 
 gen adj=.
* gen tol=log(1.03)
 replace adj=1 if diff_n>0
  replace adj=0 if diff_n==0
 
 
 
  gen region=0 
 replace region=1 if province==11|province==12|province==13|province==21|province==31|province==11| ///
 province==32|province==33|province==35|province==37|province==44|province==46
 
 gen did_region=did* region
gen lnabsG_gdp=ln(absG_gdp)

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
drop if VMPL<0



*----------------------------------------------------------------------------------
*12.1. agglomeration
reghdfe lnabsG_gdp did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity  Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_l,    ///
absorb(t newid) cluster (ind4year)  

*----------------------------------------------------------------------------------
*12.2. import competition
reghdfe lnabsG_gdp did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity  Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_imp,    ///
absorb(t newid) cluster (ind4year)  
*----------------------------------------------------------------------------------
*12.3. agglomeration+import competition+fdi

reghdfe lnabsG_gdp did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity  Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_l agg_imp agg_fdi,    ///
absorb(t newid) cluster (ind4year) 
*----------------------------------------------------------------------------------

*12.4 export market expansion
reghdfe lnabsG_gdp did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity  Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ave_export,    ///
absorb(t newid) cluster (ind4year)  
*----------------------------------------------------------------------------------

*12.5.  labor adjustment

reghdfe adj did Llnl Ltfp_op   Llnage  LlnkL  LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind if lnabsG_gdp!=.,    ///
absorb(t newid) cluster (ind4year)  


*================================================================================================


*---------------------------------------
* Part II: for capital efficiency gaps
*---------------------------------------

cd "D:\Nanjing\2020\wage gap\Replication"
use "labor-basic-tpu-reg-1.dta",clear

 gen VMPK=capitale*(y_ind_add1/k)

drop if VMPK<0




*1. generate capital category:
bysort id: gen indc_n=_n==1
gen m_k=k if indc_n==1
bysort id: egen M_k=max(m_k)

egen p1=pctile(M_k), p(25)
egen p2=pctile(M_k), p(50)
egen p3=pctile(M_k), p(75)
gen size_k=0
replace size_k=1 if M_k<=p1
replace size_k=2 if M_k>p1&M_k<p2
replace size_k=3 if M_k>p2&M_k<p3
replace size_k=4 if M_k>p3

 bysort t indc: egen agg_l=sum(n)
 gen l_s=n/agg_l
 
*2. generate average rental rate in each category:
bysort city ind4_adj QiuType size_k t: egen r_rate=sum(l_s*VMPK) if inv>0
*bysort county ind4_adj QiuType size_k t: egen r_rate=mean(VMPK) if inv>0


* 3. gap measured in capital:

gen gdp_def=1
replace gdp_def=1.077 if t==1999
replace gdp_def=1.077*1.085 if t==2000
replace gdp_def=1.077*1.085*1.083 if t==2001
replace gdp_def=1.077*1.085*1.083*1.091 if t==2002
replace gdp_def=1.077*1.085*1.083*1.091*1.10 if t==2003
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201 if t==2004
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114 if t==2005
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127 if t==2006
replace gdp_def=1.077*1.085*1.083*1.091*1.10*1.201*1.114*1.127*1.142 if t==2007



gen gap_k=VMPK-r_rate
gen abs_G_k=abs(gap_k)
gen lnabs_k=log(abs_G_k)



  rename citycode city
  merge m:m city ind4_adj t using  "city1998-2007.dta" 

  rename city_cic4_value import
keep if _merge==1|_merge==3
replace import=1 if import==.

drop _merge 

 merge m:m city ind4_adj t using  "fdi1998-2007.dta" 
rename city_cic_fdi fdi
replace fdi=1 if fdi==0
keep if _merge==3

rename city citycode
cap drop agg_l
gen num=1
bysort citycode ind4_adj t: egen agg_num=sum(num) /*number of firms at city-industry-year level*/
bysort citycode ind4_adj t: egen agg_rev=sum(s_rev) /*city-industry-year level sales*/
bysort citycode ind4_adj t: egen agg_l=sum(cap)      /*city-industry-year level capital scale*/
bysort ind4_adj t: egen  agg_firm=sum(num)   /*city-industry-year level number of firms*/



replace agg_num=log(agg_num)
replace agg_rev=log(agg_rev)
replace agg_l=log(agg_l)
gen agg_imp=log(import)
gen agg_fdi=log(fdi)
gen ave_export=s_ind_exp/agg_firm
replace ave_export=log(ave_export)
replace ave_export=0 if ave_export==.
/*
duplicates drop newid t, force
xtset newid t
bysort newid: gen Lagg_imp=l.agg_imp
bysort newid: gen Lagg_l=l.agg_l
*/

 egen provyear=group(province  t)
 egen ind2year=group(ind2_adj  t)
 egen owneryear=group(QiuType  t)
 egen provowneryear=group(province QiuType  t)
 egen ind4year=group(ind4_adj  t)

 
 gen lnn=log(n)
 sort newid t
 xtset newid t
 bysort newid: gen lnk_l=l.lnk
 gen diff_n=abs(lnk-lnk_l)
 


bysort ind4_adj t QiuType province: egen ub_n=pctile(diff_n), p(15)

 gen adj=.
* gen tol=log(1.03)
 replace adj=1 if diff_n>ub_n
  replace adj=0 if diff_n<=ub_n 
 
 
 
  gen region=0 
 replace region=1 if province==11|province==12|province==13|province==21|province==31|province==11| ///
 province==32|province==33|province==35|province==37|province==44|province==46
 
 gen did_region=did* region
gen lnabsG_gdp=ln(absG_gdp)

winsor2 tfp_op lnabsG_gdp lnage  finance2  lnkL rate , replace cuts(1 99) trim
winsor2 lnRD, replace cuts(0 99) trim
*drop if VMPL<0



*-----------------------------------------------------------------
*12.6 agglomeration
reghdfe lnabs_k did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_l,    ///
absorb(t newid) cluster (ind4year)  


*12.7 import competition
reghdfe lnabs_k did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_imp,    ///
absorb(t newid) cluster (ind4year)  

*12.8 agglomeration+import competition+fdi

reghdfe lnabs_k did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind agg_l agg_imp agg_fdi,    ///
absorb(t newid) cluster (ind4year) 


*12.9 export market expansion
reghdfe lnabs_k did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind ave_export,    ///
absorb(t newid) cluster (ind4year)  


*12.10  labor adjustment

reghdfe adj did Llnl Ltfp_op   Llnage  LlnkL LlnRD  export_intensity Lfinance2 ///
 Ltariff_input Ltariff_output post_kl_1998 Lhhi5_lns_ind Llnk_ind if lnabs_k!=.,    ///
absorb(t newid) cluster (ind4year)  


